<?php
require_once('../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/local/blackboxsurvey/forms.php");
define('AJAX_SCRIPT', true);

//yeu cau login,sau khi login tu dong chuyen sang trang chu
global $USER;
if ($USER->id == null){
    $SESSION->homepage = true;
    require_login($SITE);
}
if($SESSION->homepage){
    $SESSION->homepage = null;
    redirect( $CFG->wwwroot);
}

//object class
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questionaire.php");

$id_qn = optional_param('id_qn',null, PARAM_TEXT);
$id_output = optional_param('id_output',null, PARAM_TEXT);
$action = optional_param('action',null, PARAM_TEXT);
$path_image = $CFG->wwwroot .'/local/blackboxsurvey/image/';
/* Viet doan code cua ban o day */
$array['id_qn'] = $id_qn;
if($action == 'edit')
{
    //load noi dung output
    $c_qn = new b_questionaire();
    $output = $c_qn->get_output_by_ID($id_output);
    $array['id'] = $id_output;
    $array['content'] = $output->content;
}
$array['action'] = $action;

$mform = new form_add_new_inout_questionaire(null, $array);

//
if ($fromform = $mform->get_data())
{	
    //du lieu can cho viec update
    $id_qn = $fromform->txtidqn;
    $id_output = $fromform->txtid;
    $content = $fromform->txtcont;
    $action = $fromform->txtaction;
	
    //echo "<script>alert('".$question['id_type']."');</script>";
    $c_qn = new b_questionaire();
    if($action == 'add')
        $c_qn->add_new_output_questionaire($id_qn,$content);
    elseif($action == 'edit')
        $c_qn->edit_new_output_questionaire($id_output,$content);
    
	//close colorbox
	echo "<script>parent.$.fn.colorbox.close(); </script>";
}


$mform->display();
/*------Ket thuc doan code cua ban-------*/

